#{extends 'backend_main.html' /}
#{set title:'后台管理' /}
<script type="text/javascript" charset="utf-8" src="/public/neditor-prod/neditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/neditor-prod/neditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/public/neditor-prod/neditor.service.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/public/neditor-prod/i18n/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/public/neditor-prod/third-party/browser-md5-file.min.js"></script>
    <div class="x-body">
        <form class="layui-form">
          <input type="hidden" id="id" name="id" value="${item?.id}">
          <input type="hidden" id="filename" name="filename" value="${item?.filename}">
            <div class="layui-row">
                <div class="layui-col-md5">
                    <div class="layui-form-item">
                        <label for="customer_name" class="layui-form-label">
                            <span class="x-red">*</span>所属频道
                        </label>
                        <div class="layui-input-inline">
                        #{select name:'channel_id',id:'channel_id' ,items :channelList,value:item?.channel_id, labelProperty:"channel_name", valueProperty:"id"}#{/select}
                        </div>
                    </div>
                </div>
                <div class="layui-col-md5">
                    <div class="layui-form-item">
                        <label for="customer_name" class="layui-form-label">
                            <span class="x-red">*</span>阅读次数
                        </label>
                        <div class="layui-input-inline">
                            <input class="layui-input" placeholder="阅读次数" name="read_count" id="read_count" value="${item?.read_count}">
                        </div>
                    </div>
                </div>
            </div>

          <div class="layui-form-item">
              <label for="customer_name" class="layui-form-label">
                  <span class="x-red">*</span>文章标题
              </label>
              <div class="layui-input-block">
                  <input type="text" id="title" name="title" required="" lay-verify="required|title" autocomplete="off" class="layui-input"
                         value="${item?.title}">
              </div>
          </div>
          <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>图片
                </label>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="uploadImg">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-input-inline">
                    #{if item!=null}
                        <img src="/FileController/images?uuid=${item?.filename}" width="200" height="100" id="imgView" name="imgView" onclick="layerPhotos({src:this.src})">
                    #{/if}
                    #{else }
                        <img src="/public/images/favicon.png" width="200" height="100" id="imgView" name="imgView" onclick="layerPhotos({src:this.src})" />
                    #{/else}
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label for="common" class="layui-form-label">
                    摘要
                </label>
                <div class="layui-input-block">
                    <input placeholder="摘要" id="summary" name="summary" lay-verify="summary" class="layui-input" value="${item?.summary}">
                </div>
            </div>
          <div class="layui-form-item layui-form-text">
              <label for="common" class="layui-form-label">
                  内容
              </label>
              <div class="layui-input-block">
                  <script type="text/plain" id="content" name="content">
                  </script>
                  <script>
                      $(function () {
                          //window.UEDITOR_HOME_URL = "/public/neditor/";
                          var ue = UE.getEditor('content',{initialFrameHeight:500});
                          ue.ready(function () {
                              var isAppendTo = false;
                              var htmlTmp = '${item?.content.raw()}';
                              if(htmlTmp!='null' && htmlTmp !=''){
                                  ue.setContent(htmlTmp, isAppendTo);
                              }
                          });
                      });
                  </script>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer','upload','laydate'], function(){
          var $ = layui.jquery;
          var form = layui.form,layer = layui.layer;
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#buy_date' //指定元素
            });
          //自定义验证规则
          form.verify({
              title: function(value){
              if(value.length < 2){
                return '标题至少得2个字符啊';
              }
            }
          });
          //监听提交
          form.on('submit(add)', function(data){
            console.log(JSON.stringify(data.field));
             //发异步，把数据提交给php
              $.ajax({
                  type:"POST",                      //请求类型
                  url:"./newsEdit?v=add",                 //URL
                  data:data.field,                  //传递的参数
                  dataType:"json",                 //返回的数据类型
                  success:function(data){          //data就是返回的json类型的数据
                      console.log(data);
                      layer.alert(data.msg, {icon: 6},function () {
                          parent.window.location.reload();
                      });
                  }
              });
            return false;
          });
        });
    </script>
